package result

import (
	"net/http"
)

type Result struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

const (
	CodeOK                  = http.StatusOK
	CodeBadRequest          = http.StatusBadRequest
	CodeUnauthorized        = http.StatusUnauthorized
	CodeForbidden           = http.StatusForbidden
	CodeInternalServerError = http.StatusInternalServerError
)

func Success(data any) *Result {
	return &Result{Code: CodeOK, Msg: "success", Data: data}
}

func Fail(code int, error string) *Result {
	return &Result{Code: code, Msg: "error", Data: error}
}

func Abort(code int, data any) *Result {
	return &Result{Code: code, Msg: "abort", Data: data}
}
